import { unInstance } from '@/service'
import { useAuthStore } from '@/store'
import { getEnv } from '@/utils/shared.ts'

interface RESPONSE {
  status: string
  message: string
  data: any
}

export default {
  /* 下载图片 */
  downloadImage(imageId: string, bindingType: string = '1') {
    const { sessionid, token } = storeToRefs(useAuthStore())
    return new Promise<string>((resolve) => {
      uni.downloadFile({
        url: `${
          getEnv().apiBase
        }/napFileApi/merchant/common/file/download?sessionid=${
          sessionid.value
        }&bindingType=${bindingType}&imageId=${imageId}`, // 仅为示例，并非真实的资源
        header: {
          "X-Authorization": `Bearer ${token.value}`,
        },
        success: (res) => {
          if (res.statusCode === 200) {
            resolve(res.tempFilePath);
          }
        },
      });
    })
  },
  /* 删除图片 */
  delImage(imageId: string, type: string = '1') {
    const { sessionid, token } = storeToRefs(useAuthStore())
    return new Promise<string>((resolve) => {
      uni.request({
        url: `${ getEnv().apiBase }/napFileApi/merchant/common/file/del`,
        data: {
          sessionid: sessionid.value,
          bindingType: type,
          imageId,
        },
        method: 'POST',
        header: {
          "X-Authorization": `Bearer ${token.value}`,
        },
        success: (res) => {
          if (res.statusCode === 200) {
            resolve(res);
          }
        },
      })
    })
  },
}
